struct _KewComponentObject {
    KewObject super;
    
    KewComponentObject *parent;
    KewBlockObject *access_violation_block;
    KewMapObject *activators; /* from MIME type to ActivationBlock */
    KewMapObject *services; /* from Identifier to service object */
};

void kew_container_activate(KewContainerObject *container,
                            KewObject *type,
                            KewObject *data,
                            KewObject **args,
                            KewObject **results)
{
    KewObject *send_args[2];
    
    KewObject *activator = kew_send_1_1(activators, sel_at, type);
    send_args[0] = container;
    send_args[1] = args[0];
    kew_send(activator, sel_call, KEW_CALL_SHAPE(2, KEW_CALL_SHAPE_MULTI(1), 1, 0), send_args, results);
}


/* This is called (mainly by the Kew VM) to ensure that an object from one container has the right to
 * do something encapsulation-breaking to an object from the other.
 * It boils down to which container "owns" the other.
 */

/* FIXME: ensure that the VM has a root container defined, and doesn't rely on NULL */
void kew_container_check_access(KewContainerObject *source, KewContainerObject *dest)
{
    /* Chase up the container hierarchy in the destination, and look for the source
     * (i.e. verify source is actually a parent of dest)
     */    
    while (dest != NULL && dest != source)
        dest = dest->parent;

    /* If we've visited all the parents of dest and didn't find source, access is not allowed. */
    if (dest == NULL)
        kew_send_1_0(dest->access_violation_block, sel_call, source);
}


/***********************************/

KEW_METHOD(Activator_kew_source)
{
    /* compile and produce a kew bytecode type component, then recall same container to activate it */
    /* FIXME */
}

KEW_METHOD(Activator_kew_bytecode)
{
    KewComponentObject *component = kew_type_check(args[1], &kew_component_type);

    if (component->activation_cache == NULL) {
        KewContainerObject *container = kew_type_check(args[0], &kew_container_type);

        component->activation_cache = bytecode;
        /* FIXME.... */
    }
}

/* This one is interesting - we want to know whether we're allowing this to be activated even
 * In many containers it would make sense to associate the MIME type with a new activator
 * that simply bails out or to remove the activator from the map - note that this might allow
 * a client to gain information about what it is allowed to do, so replacing is probably better
 * than removing the activator */
KEW_METHOD(Activator_kew_native)
{
}